//
//  SCMYModel.m
//  ScalperMerchant
//
//  Created by 王云 on 2017/10/10.
//  Copyright © 2017年 WY. All rights reserved.
//

#import "SCMYModel.h"

@implementation SCMYModel

+ (void)GetMineData:(NSDictionary *)userData{
    
    SCUser *userInfo  = [SCUserTool loadInfo];
    userInfo.store_name = [userData hw_safeObjectForKey:@"store_name"];
    userInfo.bd_name = [userData hw_safeObjectForKey:@"bd_name"];
    userInfo.bd_phone = [userData hw_safeObjectForKey:@"bd_phone"];
    
    NSDictionary *credit = [userData hw_safeObjectForKey:@"credit"];
    userInfo.credit_total = [credit hw_safeObjectForKey:@"credit_total"];
    userInfo.credit_coupon_consumed = [credit hw_safeObjectForKey:@"credit_coupon_consumed"];
    userInfo.credit_coupon_assigned = [credit hw_safeObjectForKey:@"credit_coupon_assigned"];
    userInfo.credit_undefined = [NSString stringWithFormat:@"%@",[credit hw_safeObjectForKey:@"credit_undefined"]];
    
    userInfo.credit_coupon_sold = [userData hw_safeObjectForKey:@"credit_coupon_sold"];
    
    
    userInfo.joinin_time = [NSString stringWithFormat:@"%@",[userData hw_safeObjectForKey:@"joinin_time"]];
    
    NSArray *dataArr = [ZYUserDefaults objectForKey:KGoodsclass];
    for (NSDictionary *jdDic in dataArr) {
        NSString *gcID = [NSString stringWithFormat:@"%@",[jdDic hw_safeObjectForKey:@"gc_id"]];
        if ([gcID isEqualToString: [NSString stringWithFormat:@"%@",[userData hw_safeObjectForKey:@"sc_id"]]]) {
             userInfo.gc_name = [jdDic hw_safeObjectForKey:@"gc_name"];
        }
    }
    userInfo.gc_id = [userData hw_safeObjectForKey:@"sc_id"];

   
    
    userInfo.contacts_name = [userData hw_safeObjectForKey:@"contacts_name"];
    
     NSString *contactsphone = [NSString stringWithFormat:@"%@",[userData hw_safeObjectForKey:@"store_phone"]];
    if ([contactsphone isEqualToString:@"<null>"]) {
        userInfo.contacts_phone = @"";

    }else{
        userInfo.contacts_phone = [NSString stringWithFormat:@"%@",[userData hw_safeObjectForKey:@"contacts_phone"]];
    }
    
    if (![[userData hw_safeObjectForKey:@"boss_name"] isKindOfClass:[NSNull class]]) {
        userInfo.boss_name = [userData hw_safeObjectForKey:@"boss_name"];
    }else{
        userInfo.boss_name = @"";
    }
   
    NSString *store_phone = [NSString stringWithFormat:@"%@",[userData hw_safeObjectForKey:@"store_phone"]];
    if ([store_phone isEqualToString:@"<null>"]) {
        userInfo.store_phone = @"";
    }else{
        userInfo.store_phone = [NSString stringWithFormat:@"%@",[userData hw_safeObjectForKey:@"store_phone"]];
    }

    if ([userData hw_safeObjectForKey:@"joinin_state"]) {
        
        NSString *joinStr = [NSString stringWithFormat:@"%@",[userData hw_safeObjectForKey:@"joinin_state"]];
        
        if (![joinStr isEqualToString:userInfo.joinin_state]) {
            [SCApiTool ScRefreshSuccess:^(NSArray *data) {
            } failure:^(NSString *errormsg) {
            }];
            return;
        }
        userInfo.joinin_state = [NSString stringWithFormat:@"%@",joinStr];
    }
    
    if ([userData hw_safeObjectForKey:@"store_banner"]) {
        userInfo.store_banner = [NSString stringWithFormat:@"%@",[userData hw_safeObjectForKey:@"store_banner"]];
    }
    userInfo.store_type = [[userData hw_safeObjectForKey:@"store_type"] integerValue];
    
    [SCUserTool saveData:userInfo];
}


@end
